package com.d2rv.collision;

import processing.core.PApplet;
import processing.core.PImage;

/**
 * This class is used in order to detect if the user enter in a zone of collision in the collision map
 * @author Darrieutort A., Dupouy A., Rossignol L., Van Poucke A.
 */
public class Collision {

    private PImage collisionmap;

    /**
     * Default constructor. 
     * @param parent The current application
     * @param path The path of the collision map
     */
    public Collision(PApplet parent, String path) {
        this.collisionmap = parent.loadImage(path);
    }

    /**
     * Returns the color in the collision map at x,y .
     * @param x the x coordinate of the point to test
     * @param y the y coordinate of the point to test
     * @param parent
     * @return the color in the collision map at x,y 
     */
    public int getColorAt(int x, int y, PApplet parent) {
        int c = this.collisionmap.get(x+this.collisionmap.width/2, y+this.collisionmap.height/2);
        return (int) parent.red(c);
    }
}